﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Enum;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using IntelligentAgriculture.WebAPI.Application.Command.UserCommand;
using IntelligentAgriculture.WebAPI.Filter;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 羊场设置
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AllowAnonymous]
    public class SheepController : ControllerBase
    {

        private readonly ISheepService _sheepService;
        private readonly TokenService _tokenService;
        private readonly ILogger<UserController> _logger;
        private readonly IMediator _mediator;


        public SheepController(ISheepService sheepService
            , TokenService tokenService
            , ILogger<UserController> logger, IMediator mediator)
        {
             _sheepService = sheepService;
            _tokenService = tokenService;
            _logger = logger;
            _mediator = mediator;

        }
        /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<SheepOutPut>>> SheepList(SheepInPut input)
        {
            var command = new SheepQueryCommand(input);
            var roles= await _mediator.Send(command);
            return roles;
        }

        /// <summary>
        /// 生成雪花ID
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult SnowList(int count)
        {
            List<long> list=new List<long>();
            for (int i = 0; i < count; i++)
            {
                var snowId=YitIdHelper.NextId();
                list.Add(snowId);
            }
             return Ok(list);
        }

        /// <summary>
        /// 羊场添加
        /// </summary>
        /// <param name="sheepInPut"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddSheep(SheepCreateCommand command)
        {  
            return await _mediator.Send(command);
        }



        /// <summary>
        /// 单删/批删
        /// </summary>
        /// <param name="sheepId"></param>
        /// <param name="idList"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DeleteSheep(int sheepId, params int[] idList)
        {
           var command = new SheepDeleteCommand(sheepId, idList.ToArray());
           return await _mediator.Send(command);
        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdateSheep(SheepUpdateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<SheepOutPut>> GetSheep(SheepGetInPut input)
        {
            var command = new SheepGetCommand(input);
            var roles = await _mediator.Send(command);
            return roles;

        }


      


    }




}
